<template>
  <div class="body">
    <!-- 搜索 -->
    <div class="ser_div">
      <el-row>
        <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 订单号 </el-col>
            <el-col :span="16">
              <el-input v-model="ser.order_number" type="number"></el-input>
            </el-col>
          </el-row>
        </el-col>
        <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 流水号 </el-col>
            <el-col :span="16">
              <el-input v-model="ser.serial_number"></el-input>
            </el-col>
          </el-row>
        </el-col>
        <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 客户 </el-col>
            <el-col :span="16">
              <el-select v-model="ser.customer_id" filterable placeholder="请选择客户" style="width: 100%">
                <el-option v-for="(item, index) in CustomerList" :key="index" :label="item.customer_name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-col>
          </el-row>
        </el-col>
        <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 产品 </el-col>
            <el-col :span="16">
              <el-select v-model="ser.product_id" filterable @change="product_id_change" placeholder="请选择产品"
                style="width: 100%">
                <el-option v-for="(item, index) in productList" :key="index" :label="item.product_name" :value="item.id">
                </el-option>
              </el-select>
            </el-col>
          </el-row>
        </el-col>
        <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 型号 </el-col>
            <el-col :span="16">
              <el-select filterable v-model="ser.model_number_id" placeholder="请选择型号" style="width: 100%">
                <el-option v-for="(item, index) in ModelNumberList" :key="index" :label="item.model_number"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-col>
          </el-row>
        </el-col>
        <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 订单日期范围 </el-col>
            <el-col :span="16">
              <el-date-picker v-model="order_data" @change="order_data_change" value-format="yyyy-MM-dd" type="daterange"
                range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
              </el-date-picker>
            </el-col>
          </el-row>
        </el-col>
        <el-col>
          <el-button @click="search(0)" class="add_btn" icon="el-icon-search">查询</el-button>
          <el-button @click="searchreset" icon="el-icon-refresh" class="add_btn">重置</el-button>
          <!-- <el-button @click="search(2)" icon="el-icon-plus" class="add_btn"
            >导出</el-button
          > -->
        </el-col>
      </el-row>
    </div>

    <el-table :data="ChildList" style="width: 100%" v-loading="loading" header-cell-class-name="header_style" border>
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-table :data="props.row.order_second">
            <el-table-column label="产品类型" width="150">
              <template slot-scope="prop">
                <span>{{
                  prop.row.models ? prop.row.models.modelname : ""
                }}</span>
              </template>
            </el-table-column>
            <el-table-column label="产品" width="150">
              <template slot-scope="prop">
                <span>{{
                  prop.row.product ? prop.row.product.product_name : ""
                }}</span>
              </template>
            </el-table-column>
            <el-table-column label="型号" width="150">
              <template slot-scope="prop">
                <span>{{
                  prop.row.model_number
                  ? prop.row.model_number.model_number
                  : ""
                }}</span>
              </template>
            </el-table-column>
            <!-- <el-table-column label="颜色" width="150">
              <template slot-scope="prop">
                <span>{{ prop.row.color ? prop.row.color.color : "" }}</span>
              </template>
            </el-table-column> -->
            <el-table-column label="规格" width="150">
              <template slot-scope="prop">
                <span>{{
                  prop.row.specification
                  ? prop.row.specification.specification
                  : ""
                }}</span>
              </template>
            </el-table-column>
            <!-- <el-table-column label="订单进度(已完成 / 未领取 / 生产中)">
              <template slot-scope="prop">
                <div class="uls">
                  <div v-for="(ite, index) in prop.row.job_type_list" :key="index" :class="[
                    'lis',
                    ite.scz_count == 0 && ite.wlq_count == 0 ? 'wancheng'
                      : ite.scz_count > 0 ? 'unwancheng' : 'unpush', (ite.is_appoint == 2) &
                    (ite.is_epiboly == 1),
                  ]">
                    <span style="font-size: 12px; font-size: 10px">{{
                      ite.job_type ? ite.job_type.job_type : ""
                    }}</span>
                    <div style="
                        display: flex;
                        align-items: center;
                        width: 100%;
                        justify-content: space-between;
                      ">
                      <span>{{ ite.ywc_count }}</span>/ <span>{{ ite.wlq_count }}</span>/
                      <span>{{ ite.scz_count }}</span>
                    </div>
                  </div>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="详情" width="250">
              <template slot-scope="prop">
                <el-button type="text" :disabled="prop.row.is_kucun == 1" v-permission="['dingdanjindu_more']"
                  @click="set_products(prop.row)">领单详情</el-button>
                <el-button @click="set_yuangong(prop.row, 2)" :disabled="prop.row.is_kucun == 1" type="text">外包</el-button>
                <el-button @click="set_yuangong(prop.row, 1)" :disabled="prop.row.is_kucun == 1" type="text">指派</el-button>
              </template>
            </el-table-column> -->
          </el-table>
        </template>
      </el-table-column>
      <el-table-column prop="id" label="ID" width="60"> </el-table-column>
      <el-table-column prop="order_number" label="订单号" width="80">
      </el-table-column>
      <el-table-column prop="serial_number" label="流水号" width="80">
      </el-table-column>
      <el-table-column prop="serial_number" label="客户名称" width="100">
        <template slot-scope="scope">
          {{ scope.row.customer ? scope.row.customer.customer_name : "" }}
        </template>
      </el-table-column>

      <!-- <el-table-column prop="order_date" label="业务员" width="80">
        <template slot-scope="scope">
          {{ scope.row.account_executive.company_name }}
        </template>
      </el-table-column> -->

      <el-table-column prop="order_date" label="产品名称" width="80">
        <template slot-scope="scope">
          {{ scope.row.product ? scope.row.product.product_name : "" }}
        </template>
      </el-table-column>
      <el-table-column prop="order_date" label="型号" width="80">
        <template slot-scope="scope">
          {{
            scope.row.model_number ? scope.row.model_number.model_number : ""
          }}
        </template>
      </el-table-column>
      <!-- <el-table-column  label="型号图片" width="80">
        <template slot-scope="scope">
          <img :src="uploadImgUrl+scope.row.model_number.file.file_url" @click="push_img(scope.row)"  style="cursor: pointer;display:block;width:60px;display: block;margin: 0 auto;" v-if="scope.row.model_number.file!=null"/>
          <img src="../../../src/assets/zwtp.jpg" style="width:60px;display: block;margin: 0 auto;"  v-else/> 
        </template>
      </el-table-column> -->
      <el-table-column label="规格" width="80">
        <template slot-scope="scope">
          {{
            scope.row.specification ? scope.row.specification.specification : ""
          }}
        </template>
      </el-table-column>


      <!-- <el-table-column label="颜色" width="80">
        <template slot-scope="scope">
          {{ scope.row.color ? scope.row.color.color : "" }}
        </template>
      </el-table-column> -->
      <el-table-column label="订单进度(已完成 / 未领取 / 生产中)" width="500">
        <template slot-scope="prop">
          <div class="uls">
            <div v-for="(ite, index) in prop.row.order_child" :key="index" :class="[
              'lis',
              ite.scz_count == 0 && ite.wlq_count == 0 ? 'wancheng'
                : ite.scz_count > 0 ? 'unwancheng' : 'unpush', (ite.is_appoint == 2) & (ite.is_epiboly == 1),
            ]">
              <span style="font-size: 12px; font-size: 10px">{{
                ite.job_type ? ite.job_type.job_type : ""
              }}</span>
              <span style="
                      font-size: 14px;
                      transform: scale(0.8, 0.8);*font-size:12px;">{{ ite.employee ? ite.employee.employee_name : ''
                      }}</span>
              <div style="
                        display: flex;
                        align-items: center;
                        width: 100%;
                        justify-content: space-between;
                      ">
                <span>{{ ite.ywc_count }}</span>/ <span>{{ ite.wlq_count }}</span>/
                <span>{{ ite.scz_count }}</span>
              </div>
            </div>
          </div>
        </template>
      </el-table-column>

      <el-table-column prop="num" label="数量" width="80"> </el-table-column>
      <el-table-column prop="remark" label="备注" width="450">
      </el-table-column>
      <el-table-column label="紧急程度" width="80">
        <template slot-scope="scope">
          <span v-if="scope.row.emergency_procedure == 1" style="color: #333">普通</span>
          <span v-if="scope.row.emergency_procedure == 2" style="color: #1890ff; font-weight: bold">紧急</span>
          <span v-if="scope.row.emergency_procedure == 3" style="color: #ff0000; font-weight: bold">十万火急</span>
        </template>
      </el-table-column>
      <el-table-column prop="order_date" label="下单日期" :formatter="formatterTime" width="100">
      </el-table-column>
      <el-table-column prop="delivery_date" label="交货日期" :formatter="formatterTime" width="100">
      </el-table-column>
      <!-- <el-table-column label="审核状态" width="80">
        <template slot-scope="scope">
          {{ scope.row.status == 1 ? "已通过" : "未审核" }}
        </template>
      </el-table-column> -->
      <el-table-column label="操作" width="280" fixed="right">
        <template slot-scope="scope">

          <el-button type="text" :disabled="scope.row.is_kucun == 1" v-permission="['dingdanjindu_more']"
            @click="set_products(scope.row)">领单详情</el-button>
          <!-- v-if="prop.row.draw_time == null && prop.row.is_epiboly == 2" -->
          <el-button @click="set_yuangong(scope.row, 2)" :disabled="scope.row.is_kucun == 1" type="text">外包</el-button>
          <!-- v-if="prop.row.draw_time == null && prop.row.is_epiboly == 2" -->
          <el-button @click="set_yuangong(scope.row, 1)" :disabled="scope.row.is_kucun == 1" type="text">指派</el-button>


          <el-popconfirm v-permission="['dingdanjindu_shanchu']" style='margin-left:10px' confirm-button-text="确定"
            cancel-button-text="取消" icon="el-icon-info" icon-color="red" title="确定删除此订单吗？"
            @confirm="del_Order(scope.row.id)">
            <el-button slot="reference" type="text">删除</el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" background @prev-click="prev"
        @next-click="next" :current-page.sync="pagination.page" :page-size="pagination.per_page"
        layout="total, prev, pager, next" :total="total">
      </el-pagination>
    </div>

    <el-dialog title="生产信息" :visible.sync="isset_1" width="30%" :close-on-click-modal="false" @close="close_dialog">
      <el-row v-if="push_order.is_epiboly == 1">
        <el-col>
          <span style="color: crimson; font-size: 16px">*当前订单已外包*</span>
        </el-col>
      </el-row>
      <el-row v-if="push_order.is_appoint == 1">
        <el-col>
          <span style="color: crimson; font-size: 16px">*当前订单已指派*</span>
        </el-col>
      </el-row>
      <!-- <el-row
        style="height: 40px;line-height: 40px;display: flex;align-items: center;">
        <el-col :span="3"> 工序ID </el-col>
        <el-col :span="21">
          {{ push_order.id }}
        </el-col>
      </el-row> -->
      <el-row style="
          height: 40px;
          line-height: 40px;
          display: flex;
          align-items: center;
        ">
        <el-col :span="3"> 当前工序 </el-col>
        <el-col :span="21" v-if="push_order.job_type">
          {{ push_order.job_type.job_type }}
        </el-col>
      </el-row>
      <el-row v-if="push_order.is_epiboly != 1" style="
          height: 40px;
          line-height: 40px;
          display: flex;
          align-items: center;
        ">
        <el-col :span="3"> 领单人 </el-col>
        <el-col :span="21">
          <el-select v-model="push_order.employee_user_id" placeholder="请选择工人" style="width: 100%">
            <el-option v-for="(item, index) in pushCustomerList" :key="index" :label="item.employee.employee_name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button @click="isset_1 = false" type="primary" size="small">取消</el-button>
        <el-button @click="push_set_1" v-permission="['dingdanjindu_pushset']" type="primary" size="small">确定</el-button>
      </span>
    </el-dialog>

    <el-dialog title="生产订单领取及完成情况表" :visible.sync="isProducts" width="50%" :close-on-click-modal="false"
      @close="isProducts_close">
      <el-row style="
          height: 50px;
          line-height: 50px;
          display: flex;
          align-items: center;
        ">
        <el-col :span="3" style="text-align: center"> 当前工序 </el-col>
        <el-col :span="7">
          <el-select v-model="push_prders.job_type_id" placeholder="请选择工序" style="width: 100%" clearable
            @change="job_type_employee_user_1">
            <el-option v-for="(item, index) in job_type_list" :key="index" :label="item.job_type.job_type"
              :value="item.job_type.id">
            </el-option>
          </el-select>
        </el-col>
        <el-col :span="3" style="text-align: center"> 当前员工 </el-col>
        <el-col :span="7">
          <el-select v-model="push_prders.employee_user_id" placeholder="请选择员工" style="width: 100%" clearable
            @change="push_prders_change">
            <el-option v-for="(item, index) in pushCustomerList" :key="index" :label="item.employee.employee_name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-col>
        <el-col :span="4" style="text-align: center;">
          <el-checkbox v-model="is_morezhipai">外包</el-checkbox>
        </el-col>
      </el-row>
      <el-table :data="moreList" stripe @selection-change="handleSelectionChang" style="width: 100%" border>
        <el-table-column type="selection" width="55"> </el-table-column>

        <el-table-column prop="product_num" label="生产序号" width="55"> </el-table-column>

        <el-table-column prop="serial_number" label="工种" width="120">
          <template slot-scope="scope">
            <span>{{ scope.row.job_type.job_type }}</span>
          </template>
        </el-table-column>
        <el-table-column label="领单人" width="170">
          <template slot-scope="scope">
            <div style="width:100%;display:flex;align-items:center;">
              <div style="width:90px;float:left;text-align:center;">
                <span v-if="scope.row.is_epiboly == 1 || scope.row.employee"
                  :style="{ color: scope.row.is_epiboly == 1 ? 'red' : '' }">{{
                    scope.row.is_epiboly == 1
                    ? "外包"
                    : scope.row.employee.employee_name
                  }}</span>
              </div>
              <div style="width:80px;float:left;text-align:center;">
                <span v-if="!scope.row.submit_time && scope.row.status != 1" style="color:rgb(26, 132, 208);"
                  @click="zhipai_moreclick(scope.row.id)">指派</span>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="指派日期" width="170">
          <template slot-scope="scope">
            <span v-if="scope.row.is_epiboly == 1 || scope.row.employee">{{
              scope.row.is_epiboly == 1
              ? scope.row.epiboly_time
              : scope.row.appoint_time
            }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="draw_time" label="领单日期"> </el-table-column>
        <el-table-column prop="submit_time" label="完成日期"> </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="add_dayinpush_plus" type="primary" size="small">添加到打印列表</el-button>
        <el-button @click="set_OrderChildStatus()" type="primary" size="small">完成</el-button>
      </span>
    </el-dialog>

    <!-- 指派 | 外包-->
    <el-dialog :title="title_zp" :visible.sync="isset" width="30%" :close-on-click-modal="false" @close="zhpai_close"
      v-if="zhipaimore">
      <el-row style="
          height: 50px;
          line-height: 50px;
          display: flex;
          align-items: center;
        ">
        <el-col :span="3"> 订单ID </el-col>
        <el-col :span="21">
          {{ zhipaimore.order_id }}
        </el-col>
      </el-row>
      <el-row style="
          height: 50px;
          line-height: 50px;
          display: flex;
          align-items: center;
        ">
        <el-col :span="3"> 产品名 </el-col>
        <el-col :span="21">
          {{ zhipaimore.product ? zhipaimore.product.product_name : '' }}
        </el-col>
      </el-row>
      <el-row style="
          height: 50px;
          line-height: 50px;
          display: flex;
          align-items: center;
        ">
        <el-col :span="3"> 订单型号 </el-col>
        <el-col :span="21">
          {{ zhipaimore.model_number ? zhipaimore.model_number.model_number : '' }}
        </el-col>
      </el-row>
      <el-row style="
          height: 50px;
          line-height: 50px;
          display: flex;
          align-items: center;
        ">
        <el-col :span="3"> 当前工序 </el-col>
        <el-col :span="21">
          <el-select v-model="push_prder.job_type_id" placeholder="请选择工序" style="width: 100%"
            @change="job_type_employee_user">
            <el-option v-for="(item, index) in job_type_list" :key="index" :label="item.job_type.job_type"
              :value="item.job_type.id">
            </el-option>
          </el-select>
        </el-col>
      </el-row>
      <el-row v-if="title_zps == 1" style="
          height: 50px;
          line-height: 50px;
          display: flex;
          align-items: center;
        ">
        <el-col :span="3"> 员工名称 </el-col>
        <el-col :span="21">
          <el-select v-model="push_prder.employee_user_id" placeholder="请选择员工" style="width: 100%">
            <el-option v-for="(item, index) in pushCustomerList" :key="index" :label="item.employee.employee_name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-col>
      </el-row>
      <el-row style="
          height: 50px;
          line-height: 50px;
          display: flex;
          align-items: center;
        ">
        <el-col :span="3"> 订单数量 </el-col>
        <el-col :span="21">
          <el-input-number v-model="push_prder.num" :min="1" :max="zpnum.wlq_count"></el-input-number>
        </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button @click="isset = false">取消</el-button>
        <!-- 指派按钮 -->
        <el-button @click="push_set" :disabled="push_prder.num == 0" v-if="title_zps == 1">确定</el-button>

        <!-- 外包按钮 -->
        <el-button @click="set_waibaos" :disabled="push_prder.num == 0" v-if="title_zps == 2">确定</el-button>
      </span>
    </el-dialog>

    <!-- 领单详情指派 -->
    <el-dialog title="指派" :visible.sync="zhipai_more" width="20%">
      <el-select v-model="t_employee_user_id" placeholder="请选择员工" style="width: 100%" clearable>
        <el-option v-for="(item, index) in pushCustomerList" :key="index" :label="item.employee.employee_name"
          :value="item.id">
        </el-option>
      </el-select>
      <span slot="footer" class="dialog-footer">
        <el-button @click="zhipai_more = false">取消</el-button>
        <!-- 指派按钮 -->
        <el-button @click="push_set_more()">确定</el-button>
      </span>
    </el-dialog>


    <bigimg :imgurl="bigurl" :product="bigproduct" :model_number="bigmodel_number" ref="img_big"></bigimg>
  </div>
</template>
<script>
import {
  getOrderChildList,
  getUserListByJobTypeId,
  getOrderChildListByOrderId,
  assignOrderChild,
  epibolyOrderChild,
  getCustomerList,
  getModelNumberList,
  getProductList,
  addOrderPrint,
  drawOrderChildByEmployeeCardNumnber,
  delOrder,
  setOrderChildStatus,
  updateOrderChildEmployeeUserId
} from "@/api/product/index";
import bigimg from "@/components/bigimg";
export default {
  components: {
    bigimg,
  },
  data() {
    return {
      zhipai_more: false,
      t_employee_user_id: '',
      t_order_child_id: '',
      is_morezhipai: false,
      loading: true,
      order_ids: "",
      formatterTime(row, column) {
        let data = row[column.property];
        return /\d{4}-\d{1,2}-\d{1,2}/g.exec(data);
      },
      bigurl: "",
      bigproduct: "",
      bigmodel_number: "",
      uploadImgUrl: this.$global.imgQianJui,
      // 搜索
      multipleSelection: [],
      multipleSelections: [],
      ModelNumberLists: [],
      ModelNumberList: [],
      order_data: [],
      ser: {
        serial_number: "",
        model_number_id: "",
        order_number: "",
        customer_id: "",
        product_id: "",
        order_date: "",
        is_replenishment: "",
        is_stock_up: "",
        start_time: "",
        end_time: "",
      },
      CustomerList: [],
      productList: [],
      isset_1: false,
      moreList: [],
      moreLists: {},
      isProducts: false,
      customerList_s: [],

      pagination: {
        per_page: 10,
        page: 1,
      },
      total: 0,
      rules: {},
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() < Date.now() - 8.64e7;
        },
      },
      isset: false,
      ChildList: [],

      push_order: {},
      // 指派提交数据
      push_prder: {
        employee_user_id: "", //员工
        job_type_id: "", //工种
        order_id: "", //订单id
        order_second_id: "", //
        num: 0,
      },
      push_more: {},
      order_id: "",
      parent_username: "",
      job_type_list: [], //当前订单工种列表
      pushCustomerList: [], //当前指定工种员工列表
      zhipaimore: "", //指派提交数据
      zpnum: {
        scz_count: 0, //生产中
        wlq_count: 0, //未领取
        ywc_count: 0, //已完成
      },
      push_prders: {
        employee_user_id: "", //员工
        job_type_id: "", //工种
        order_id: "", //订单id
        order_second_id: "",
      },
      title_zp: "",
      wanchengs_list: [],
      title_zps: 0,
    };
  },
  mounted() {
    this.get_childList();
    this.getproduct();
    this.getModel();
    this.getCustomer();
    this.parent_username = this.$store.getters.userInfo.parent_username;
  },
  watch: {
    is_morezhipai(news, olds) {
      console.log(news)
      if (news == true) {
        this.moreList = []
        this.push_prders.job_type_id = ''
        this.push_prders.employee_user_id = ''
        let is_epiboly = 1;
        this.getOrderChild(is_epiboly)
      }
    }
  },
  methods: {
    zhipai_moreclick(id) {
      this.t_order_child_id = id
      this.zhipai_more = true
    },
    push_set_more() {
      let obj = {
        employee_user_id: this.t_employee_user_id,
        order_child_id: this.t_order_child_id,
      }
      updateOrderChildEmployeeUserId(obj).then(res => {
        if (res.code == 200) {
          this.zhipai_more = false
          this.this.t_employee_user_id=''
          this.job_type_employee_user_1(this.push_prders.job_type_id)
          this.get_childList()
        }
      })
    },
    // 外包提交
    set_waibaos() {
      epibolyOrderChild(this.push_prder).then((res) => {
        if (res.code == 200) {
          this.$message.success("外包成功");
          this.get_childList();
        }
      });
    },
    // 关闭详情
    isProducts_close() {
      this.push_prders = {
        employee_user_id: "", //员工
        job_type_id: "", //工种
        order_id: "", //订单id
        order_second_id: "",
      };
      this.moreList = [];
      this.isProducts = false
    },
    // 完成订单
    set_OrderChildStatus() {
      let child_order_ids = [];
      if (this.wanchengs_list.length > 0) {
        console.log(this.wanchengs_list);
        this.wanchengs_list.forEach((item) => {
          child_order_ids.push(item.id);
        });

        if (!this.push_prders.employee_user_id) {
          this.$message.error("请选择员工");
          return false
        } else {
          setOrderChildStatus({
            child_order_ids,
            employee_user_id: this.push_prders.employee_user_id,
          }).then((res) => {
            if (res.code == 200) {
              this.$message.success("提交成功");
              this.isProducts = false;
              this.get_childList()
            }
          });
        }
      } else {
        this.$message.error("请选择数据");
      }
    },
    push_prders_change() {
      this.is_morezhipai = false
      this.getOrderChild(2);
    },
    //获取对应子订单信息
    getOrderChild(is_epibolys) {
      getOrderChildListByOrderId({ ...this.push_prders, is_epiboly: is_epibolys }).then((res) => {
        if (res.code == 200) {
          this.moreList = res.data;
          console.log(this.moreList)
        }
      });
    },
    // 领单详情工种
    job_type_employee_user_1(val) {
      this.push_prders.employee_user_id = "";
      this.job_type_list.forEach((item) => {
        if (val == item.job_type_id) {
          this.push_prder.order_second_id = item.order_second_id;
        }
      });
      this.getOrderChild(2);
      this.getUser(val);
      this.is_morezhipai = false
    },
    // 外
    set_products(row) {
      // this.moreLists = row;
      this.push_prders.order_id = row.id;
      this.order_id = row.id;
      // this.push_prders.order_second_id = row.order_second_id;
      this.job_type_list = row.order_child;
      this.isProducts = true;
    },
    //打开指派弹窗
    set_yuangong(row, type) {
      console.log(row);
      this.title_zps = type;
      if (type == 1) {
        this.title_zp = "指派";
      } else {
        this.title_zp = "外包";
      }
      this.zhipaimore = row;
      this.isset = true;
      this.job_type_list = row.order_child;
      this.push_prder.order_id = row.id;
      this.order_id = row.id;

      console.log(this.push_prder.order_second_id)
    },
    zhpai_close() {
      this.push_prder = {
        employee_user_id: "", //员工
        job_type_id: "", //工种
        order_id: "", //订单id
        order_second_id: "", //
        num: 0,
      };
      this.isset = false;
    },
    // 指派提交
    push_set() {
      if (this.push_prder.employee_user_id == '') {
        return this.$message.error("请选择员工");
      }
      if (this.push_prder.job_type_id == '') {
        return this.$message.error("请选择工种");
      }
      assignOrderChild(this.push_prder).then((res) => {
        this.$message.success("指派成功");
        // this.isset = false;
        // this.getOrderChild(this.moreLists.id);
        this.push_prder.job_type_id = ''
        getOrderChildList({ order_id: this.order_id }).then((res) => {
          if (res.code == 200) {
            // this.ChildList = res.data.data;
            this.job_type_list = res.data.data[0].order_child;
          }
        });
        this.get_childList();
      });
    },
    job_type_employee_user(val) {
      this.getUser(val);
      this.push_prder.employee_user_id = "";
      this.job_type_list.forEach((item) => {
        if (val == item.job_type_id) {
          this.push_prder.order_second_id = item.order_second_id;
          this.zpnum.scz_count = item.scz_count;
          this.zpnum.wlq_count = item.wlq_count;
          this.zpnum.ywc_count = item.ywc_count;
          this.push_prder.num = item.wlq_count
        }
      });
    },

    del_Order(id) {
      delOrder({ id }).then((res) => {
        if (res.code == 200) {
          this.$message.success("操作成功");
          this.isProduct = false;
          this.get_childList();
        }
      });
    },
    push_img(row) {
      this.bigurl = row.model_number.file.file_url;
      this.bigproduct = row.product.product_name;
      this.bigmodel_number = row.model_number.model_number;
      this.$refs.img_big.open();
    },
    add_dayinpush() {
      if (this.multipleSelection.length == 0) {
        this.$message.error("请选择子订单");
        return false;
      }
      let noling = [];
      let ids = [];
      for (var i = 0; i < this.multipleSelections.length; i++) {
        if (
          this.multipleSelections[i].employee == null &&
          this.multipleSelections[i].is_epiboly == 2 &&
          this.multipleSelections[i].is_appoint == 2
        ) {
          this.$message.error("所选订单有未指派的订单！请指派后在添加~");
          return false;
        }
        if (!this.multipleSelections[i].draw_time) {
          let obj = {
            user_id: this.multipleSelections[i].employee_user_id,
            order_child_id: this.multipleSelections[i].id,
          };
          // 没有领单的
          noling.push(obj);
        } else {
          // 有领单的
          ids.push(this.multipleSelections[i].id);
        }
      }
      // 有领单的
      if (ids.length > 0) {
        this.dayin_2(ids);
      }
      // 没有领单的
      if (noling.length > 0) {
        noling.forEach((item) => {
          this.postw_drawOrderChildByEmployeeCardNumnber(
            item.user_id,
            item.order_child_id
          );
        });
      }
    },
    postw_drawOrderChildByEmployeeCardNumnber(user_id, order_child_id) {
      let obj = {
        order_child_id,
        user_id,
        parent_username: this.parent_username,
      };
      drawOrderChildByEmployeeCardNumnber(obj).then((res) => {
        if (res.code == 200) {
          this.getOrderChild(this.order_ids);
          this.dayin(this.order_ids, order_child_id);
        } else {
          this.$message.error("领单失败");
        }
      });
    },
    handleSelectionChang(val) {
      this.wanchengs_list = val;
    },
    // dayin
    add_dayinpush_plus() {
      let ids = []
      this.wanchengs_list.forEach(item => {
        if (item.draw_time || item.is_epiboly == 1) {
          ids.push(item.id)
        } else {
          this.$message.error("请选择已领取或外包的订单~");
        }
      })
      console.log(ids)
      this.add_dayinpush_plus_s(ids)
    },
    add_dayinpush_plus_s(ids) {
      console.log(ids, this.order_id)

      let obj = {
        order_id: this.order_id,
        order_child_ids: ids,
      };
      addOrderPrint(obj).then((res) => {
        if (res.code == 200) {
          this.$message.success("添加成功");
        }
      });
    },

    dayin_2(ids) {
      let obj = {
        order_id: this.order_ids,
        order_child_ids: ids,
      };
      addOrderPrint(obj).then((res) => {
        if (res.code == 200) {
          this.$message.success("添加成功");
        }
      });
    },
    dayin(id, ids) {
      let id_s = [];
      id_s.push(ids);
      let obj = {
        order_id: id,
        order_child_ids: id_s,
      };
      addOrderPrint(obj).then((res) => {
        if (res.code == 200) {
          this.$message.success("添加成功");
        }
      });
    },
    // 指定查询
    search(type) {
      if (type == 0) {
        this.pagination.per_page = 10;
        this.pagination.page = 1;
      }
      this.ChildList = [];
      getOrderChildList({ ...this.ser, ...this.pagination }).then((res) => {
        if (res.code == 200) {
          this.ChildList = res.data.data;
          this.total = res.data.total;
          if (type == 2) {
            if (res.data.data.length > 0) {
              this.$message.success("正在导出订单列表");
              this.exports_w();
            }
          }
        }
      });
    },
    // 导出
    exports_w() {
      let data = {
        ...this.ser,
        export: 1,
      };
      getOrderChildList_exports(data).then((res) => {
        //创建一个隐藏的a连接，
        const link = document.createElement("a");
        let blob = new Blob([res.data], { type: "application/vnd.ms-excel" });
        link.style.display = "none";
        //设置连接
        link.href = URL.createObjectURL(blob);
        link.download = "订单信息";
        document.body.appendChild(link);
        //模拟点击事件
        link.click();
      });
    },
    searchreset() {
      this.ser = {
        model_number_id: "",
        order_number: "",
        customer_id: "",
        product_id: "",
        order_date: "",
        is_replenishment: "",
        is_stock_up: "",
        start_time: "",
        end_time: "",
      };
      this.get_childList();
    },
    //客户列表
    async getCustomer() {
      await getCustomerList({ per_page: 99999 }).then((res) => {
        if (res.code == 200) {
          this.CustomerList = res.data.data;
        }
      });
    },
    //产品列表
    async getproduct() {
      await getProductList().then((res) => {
        if (res.code == 200) {
          this.productList = res.data.data;
        }
      });
    },
    // 型号列表
    async getModel() {
      await getModelNumberList().then((res) => {
        if (res.code == 200) {
          this.ModelNumberLists = res.data.data;
        }
      });
    },
    order_data_change(val) {
      this.ser.start_time = val[0];
      this.ser.end_time = val[1];
    },
    get_producModel(id) {
      getModelNumberList({
        product_id: id,
        field_list: "id,model_number",
        is_dropdown: 1,
      }).then((res) => {
        if (res.code == 200) {
          this.ModelNumberList = res.data.data;
        }
      });
    },
    product_id_change(val) {
      this.ser.model_number_id = "";
      this.get_producModel(val);
    },
    // 获取子订单
    async get_childList() {
      await getOrderChildList({ ...this.pagination, ...this.ser }).then((res) => {
        if (res.code == 200) {
          this.ChildList = res.data.data;
          this.total = res.data.total;
          this.loading = false;
        }
      });


    },
    //设置订单为已完成
    push_set_1() {
      setOrderChildStatus({
        child_order_id: this.push_order.id,
        employee_user_id: this.push_order.employee_user_id,
      }).then((res) => {
        if (res.code == 200) {
          this.$message({
            type: "success",
            message: "操作成功",
          });
          this.get_childList();
          this.isset_1 = false;
        }
      });
    },
    // // 双击打开
    // db_pushorder(row) {
    //   if (row.status != 1) {
    //     this.getUser(row.job_type.id);
    //     this.push_order = row;
    //     if (row.employee) {
    //       this.push_order.employee_user_id = row.employee.id;
    //     }
    //     this.isset_1 = true;
    //   }
    // },
    //获取指定工种员工列表
    getUser(id) {
      getUserListByJobTypeId({ job_type_id: id }).then((res) => {
        if (res.code == 200) {
          this.pushCustomerList = res.data;
        }
      });
    },
    close_dialog() {
      this.push_order = {
        id: "",
        employee_user_id: "",
        job_type: {},
      };
    },

    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pagination.page = val;
      this.get_childList();
    },
    prev() {
      this.pagination.page = this.pagination.page - 1;
      this.get_childList();
    },
    next() {
      this.pagination.page = this.pagination.page + 1;
      this.get_childList();
    },
    //获取指定工种员工列表
    getUser(id) {
      getUserListByJobTypeId({ job_type_id: id }).then((res) => {
        if (res.code == 200) {
          this.pushCustomerList = res.data;
        }
      });
    },
  },
};
</script>
<style>
.my-label {
  background: #e1f3d8;
}

/* .my-content {
    background: #dd7575;
    color: #fff;
  } */

.ul {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-items: center;
  margin-bottom: 10px;
}

.li {
  width: 32.5%;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
  box-sizing: border-box;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  -ms-box-sizing: border-box;
  -o-box-sizing: border-box;
  overflow: hidden;
  margin-top: 16px;
  margin-left: 1.02%;
}

.li:nth-child(3n-2) {
  margin-left: 0;
}

.uls {
  width: 100%;
  max-width: 100%;
  overflow-x: scroll;
  white-space: nowrap;
}

.uls .lis {
  display: inline-block;
  margin-left: 0px;
  margin-top: 5px 10px;
  box-sizing: border-box;
  border: 1px solid #fff;
  border-radius: 5px;
}

.uls .lis span {
  display: block;
  font-size: 16px;
  width: 100%;
  text-align: center;
  cursor: pointer;
  line-height: 16px;
}

.uls .lis span:nth-child(2) {
  /* margin-top: px; */
}

.wancheng {
  background: #1aa034;
  color: #fff;
}

.unwancheng {
  background: #1b8bf5;
  color: #fff;
}

.unpush {
  background: #ff6561;
  color: #fff;
}

.unwanchengs {
  background: #902c90;
  color: #fff;
}

/* .el-descriptions .is-bordered .el-descriptions-item__cell{
  padding: 5px!important;
} */

.lable_width {
  width: 100px;
}

.el-table .el-table__cell {
  /* padding: 5px 0 !important; */
}

.el-dropdown-menu {
  text-align: center;
}

.el-dropdown-menu .el-button--text {
  width: 100%;
}
</style>
